package com.guofen.controller.sjq;

import com.guofen.pojo.SjqFlocculationProduceFault;
import com.guofen.pojo.SjqFlocculationProduceMaintenanceDay;
import com.guofen.service.sjq.SjqFlocculationProduceMaintenanceDayService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/flocculationProduceMaintenanceDay")
@Controller
@Api(tags = "SjqFlocculationProduceMaintenanceDayController", description = "絮凝生产现场 设备日保养")
public class SjqFlocculationProduceMaintenanceDayController {

    @Autowired
    private SjqFlocculationProduceMaintenanceDayService sjqFlocculationProduceMaintenanceDayService;

    @ApiOperation("添加记录（操作人）")
    @RequestMapping(value = "/add_recorder", method = RequestMethod.POST)
    @ResponseBody
    public Result add_recorder(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                               @ApiParam(name="is_normal",value="是否正常",required=true) @RequestParam String is_normal,
                               @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator,
                               @ApiParam(name = "maintenance_content", value = "保养方法", required = true) @RequestParam String maintenance_content,
                               @ApiParam(name = "remarks", value = "备注", required = true) @RequestParam String remarks){
        if (sjqFlocculationProduceMaintenanceDayService.add_recorder(equipment_name, is_normal, operator, maintenance_content, remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录（检查人）")
    @RequestMapping(value = "/add_examiner", method = RequestMethod.POST)
    @ResponseBody
    public Result add_examiner(@ApiParam(name = "id", value = "记录id", required = true) @RequestParam String id,
                               @ApiParam(name = "examiner", value = "检查人", required = true) @RequestParam String examiner,
                               @ApiParam(name = "remarks", value = "备注", required = true) @RequestParam String remarks){
        if (sjqFlocculationProduceMaintenanceDayService.add_examiner(id, examiner, remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查找当天符合所提交的设备名称和保养方法的数据库中那条数据")
    @RequestMapping(value = "/getlatest", method = RequestMethod.GET)
    @ResponseBody
    public Result getlatest(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                            @ApiParam(name = "maintenance_content", value = "保养方法", required = true) @RequestParam String maintenance_content){
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.getlatest(equipment_name, maintenance_content));
    }

    @ApiOperation("查找当天符合所提交的设备名称和保养方法的数据库中那条数据")
    @RequestMapping(value = "/is_day_complete", method = RequestMethod.POST)
    @ResponseBody
    public Result is_day_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                  @ApiParam(name="maintenanceNum",value="保养方法数量",required=true) @RequestParam String maintenanceNum,
                                  @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role) {
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.is_last_complete(equipmentsName, maintenanceNum, role));
    }

    @ApiOperation("获取 当日 所有日保养记录")
    @RequestMapping(value = "/getDailyRecords",method = RequestMethod.GET)
    @ResponseBody
    public Result getDailyRecords(){
        return  ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.getDailyRecords());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="equipmentName",value="设备名称",required=true) @RequestParam String equipmentName,
                         @ApiParam(name="maintenanceContent",value="维修内容",required=true) @RequestParam String maintenanceContent,
                         @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                         @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator,
                         @ApiParam(name="examiner",value="检查人",required=true) @RequestParam String examiner,
                         @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks) {
        SjqFlocculationProduceMaintenanceDay record = new SjqFlocculationProduceMaintenanceDay();
        record.setId(id);
        record.setEquipmentName(equipmentName);
        record.setMaintenanceContent(maintenanceContent);
        record.setIsNormal(isNormal);
        record.setOperator(operator);
        record.setExaminer(examiner);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceMaintenanceDayService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
